home *** CD-ROM | disk | FTP | other *** search
/ SGI Performance Co-Pilot 1.3 / SGI Performance Co-Pilot 1.3.iso / dist6.4 / pcp.idb / usr / sbin / pmgevctr.z / pmgevctr
Text File  |  1997-04-03  |  11KB  |  488 lines

  1. #!/bin/sh 
  2. #
  3. # Copyright 1996, Silicon Graphics, Inc.
  4. # ALL RIGHTS RESERVED
  5. #
  6. # UNPUBLISHED -- Rights reserved under the copyright laws of the United
  7. # States.   Use of a copyright notice is precautionary only and does not
  8. # imply publication or disclosure.
  9. #
  10. # U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
  11. # Use, duplication or disclosure by the Government is subject to restrictions
  12. # as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
  13. # in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
  14. # in similar or successor clauses in the FAR, or the DOD or NASA FAR
  15. # Supplement.  Contractor/manufacturer is Silicon Graphics, Inc.,
  16. # 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
  17. #
  18. # THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
  19. # INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
  20. # DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
  21. # PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
  22. # GRAPHICS, INC.
  23. #
  24. # $Id: pmgevctr.sh,v 2.1 1997/03/26 02:49:08 kenmcd Exp $
  25. #
  26.  
  27.  
  28. # Break up of code
  29. # ----------------
  30. #
  31. # Get arguments
  32. #   get gadget arguments
  33. #   get pmgevctr arguments
  34. #   set remaining args as shell args
  35. # Fix up option values
  36. # Check the desired metrics
  37. # Get required metric information (use tmp files as is useful)
  38. # Print out configuration file using "here documents"
  39. # Call /usr/sbin/pmgadgets with config file
  40. #
  41.  
  42. tmp=/tmp/$$
  43. trap "rm -f $tmp.*; exit" 0 1 2 3  15
  44. rm -f $tmp.*
  45.  
  46.  
  47. # ----------------------------------------------------------
  48. # usage - print out the usage of program
  49. # ----------------------------------------------------------
  50. _usage()
  51. {
  52.     echo "Usage: $prog [options] [site [site ...]]"
  53.     echo '
  54. Options
  55.   -V                  verbose/diagnostic output
  56.  
  57. pmgadgets(1) options:'
  58.     _pmgadgets_usage
  59. }
  60.  
  61. # ----------------------------------------------------------
  62. # metric_err
  63. # ----------------------------------------------------------
  64. _metric_err()
  65. {
  66.   msg=$1
  67.  
  68.   if [ "$arch" ]
  69.   then
  70.       _pmgadgets_error "For archive \"$arch\": $msg"
  71.   else
  72.       _pmgadgets_error "For host \"$host\": $msg"
  73.   fi
  74.       
  75. }
  76.  
  77.  
  78. # ----------------------------------------------------------
  79. # metric_warn
  80. # ----------------------------------------------------------
  81. _metric_warn()
  82. {
  83.   msg=$1
  84.  
  85.   if [ "$arch" ]
  86.   then
  87.       _pmgadgets_warning "For archive \"$arch\": $msg"
  88.   else
  89.       _pmgadgets_warning "For host \"$host\": $msg"
  90.   fi
  91.       
  92. }
  93.  
  94.  
  95. # ----------------------------------------------------------
  96. # get_router_metric - 
  97. #   Get the instances from the router metric 
  98. #   Assumes $has_routers is initially true, may change it to false
  99. #   Create a $tmp.$metric.name file 
  100. # ----------------------------------------------------------
  101. _get_router_metrics()
  102. {
  103.   # metric = "send_util" OR "recv.total_util" 
  104.   metric=$1 
  105.  
  106.   # create a tmp.$metric file for the output of pminfo
  107.   rm -f $tmp.$metric
  108.  
  109.   # output metric instances
  110.   pminfo -f $info_opts $namespace hw.router.$metric > $tmp.$metric 2>&1 
  111.  
  112.   # ensure tmp.metric is likely to be ok
  113.   if grep 'inst .* value' $tmp.$metric > /dev/null
  114.   then
  115.       :
  116.   else
  117.       has_routers=false
  118.   fi
  119.  
  120.   if [ $has_routers = true ]
  121.   then
  122.       # create a tmp.$metric.name for each instance name
  123.       # each line of form:
  124.       #     inst [65792 or "router:1.1"] value 0
  125.       # output:
  126.       #     "router:1.1"
  127.       rm -f $tmp.$metric.name
  128.       sed -e 's/\]//' $tmp.$metric \
  129.       | nawk '$1 == "inst" {print $4}' > $tmp.$metric.name
  130.   fi
  131.  
  132. }
  133.  
  134. # -------------------------------------------------------
  135. # _print_router_leds -
  136. #   Print out the leds for each router for send and receive
  137. #
  138. #   Uses const:
  139. #      wrap_around
  140. #      ledX_start
  141. #      ledX_gap
  142. #      ledY_gap
  143. #      led_width
  144. #      led_height
  145. #   Uses variables:
  146. #      ledX 
  147. #      ledY
  148. # -------------------------------------------------------
  149.  
  150. _print_router_leds()
  151. {
  152.     # metric = "send_util" OR "recv.total_util" 
  153.     metric=$1
  154.  
  155.     names=`cat $tmp.$metric.name`
  156.  
  157.     for name in $names 
  158.     do
  159.       cat << EOF >> $tmp.conf
  160. _led $ledX $ledY $led_width $led_height
  161.     _update 5.000000
  162.     _metric hw.router.$metric[$name]
  163.     _legend routerLegend
  164.     _actions routerActions
  165.  
  166. EOF
  167.       ledX=`expr $ledX + $ledX_gap`;
  168.       ledX_right=`expr $ledX + $led_width`
  169.  
  170.       # start a new row if we run out of room
  171.       if [ $ledX_right -gt $wrap_around ]
  172.       then
  173.       ledX=$ledX_start 
  174.       ledY=`expr $ledY + $ledY_gap`
  175.       fi
  176.  
  177.     done # foreach name
  178. }
  179.  
  180. # ----------------------------------------------------------
  181. # --- Get arguments ---
  182.  
  183. . /usr/pcp/lib/pmgadgets-args
  184.  
  185.  
  186. # default variables
  187. verbose=false
  188. has_evctrs=true
  189. has_routers=true
  190.  
  191. _pmgadgets_args "$@"
  192.  
  193. if [ -n "$otherArgs" ]
  194. then
  195.     while getopts "?V" c $otherArgs
  196.     do
  197.     case $c
  198.     in
  199.         V)
  200.         verbose=true
  201.         ;;
  202.         '?')
  203.         _usage
  204.         exit 1
  205.         ;;
  206.     esac
  207.     done
  208.  
  209.     # set positional params to the non-option (no -) arguments
  210.     set -- $otherArgs
  211.     shift `expr $OPTIND - 1`
  212.  
  213.     # if have some non-option arguments (e.g. filenames) then error
  214.     if [ $# -gt 0 ]
  215.     then
  216.         _usage
  217.     exit 1
  218.     fi
  219. fi
  220.  
  221. # --- fix up host ---
  222. if [ "$arch" ]
  223. then
  224.      host=`pmdumplog -l $arch | awk '/^Performance/ {print $5}' | sed -e 's/,//g'`
  225.      [ ! "$host" ] && host="unknown host"
  226. else
  227.      [ ! "$host" ] && host=`/usr/bsd/hostname`
  228. fi
  229.  
  230. # --- setup some pminfo options ---
  231. if [ "$arch" ]
  232. then
  233.     info_opts="-a $arch"
  234. else
  235.     info_opts="-h $host"
  236. fi
  237.  
  238. # --- Check on metric availability ---
  239.  
  240. # check for r10k event counters
  241. event_cntrs=\
  242. "hw.r10kevctr.grad.fp \
  243.  hw.r10kevctr.pcache.imiss hw.r10kevctr.pcache.dmiss \
  244.  hw.r10kevctr.scache.imiss hw.r10kevctr.scache.dmiss \
  245.  hw.r10kevctr.tlb hw.r10kevctr.vcc \
  246. "
  247.  
  248. # check if have event counter state metric then use it
  249.  
  250. value=`pminfo $info_opts $namespace hw.r10kevctr.state 2>&1`
  251.  
  252. if expr match "$value" ".*value.*" > /dev/null
  253. then
  254.    state=`echo $value | awk '{print $2}`
  255.    case $state in
  256.      "-1") 
  257.        _metric_err "No R10000 event counters found"
  258.        ;;
  259.      "0")
  260.        _metric_err "All R10000 event counters disabled"
  261.        ;;
  262.      # Otherwise must have some event counters to use, so no error
  263.    esac
  264. else 
  265.  
  266. # check out if in namespace           
  267.  
  268.     # 1st check locally
  269.     rm -f $tmp.cntrs
  270.     pminfo $namespace $event_cntrs > $tmp.cntrs 2>&1
  271.     error=`grep 'Error' $tmp.cntrs`
  272.     if [ "$error" ]
  273.     then
  274.     bad_metric=`echo $error | awk '{print $2}' | sed -e 's/://'`
  275.     _pmgadgets_error "$bad_metric is not available in local name space"
  276.     fi
  277.  
  278.     rm -f $tmp.cntrs
  279.     pminfo $info_opts $namespace $event_cntrs > $tmp.cntrs 2>&1
  280.     error=`grep 'Error' $tmp.cntrs`
  281.     if [ "$error" ]
  282.     then
  283.     bad_metric=`echo $error | awk '{print $2}' | sed -e 's/://'`
  284.     _metric_err "$bad_metric is not available in name space"
  285.     fi
  286.  
  287.     rm -f $tmp.cntrs
  288.     pminfo -f $info_opts $namespace $event_cntrs > $tmp.cntrs 2>&1 
  289.  
  290. # check out if PMCD unable to help
  291.     error=`grep 'Unknown or illegal metric' $tmp.cntrs`
  292.     if [ "$error" ]
  293.     then
  294.     bad_metric=`echo $error | awk '{print $1}' | sed -e 's/://'`
  295.     _metric_err "PMCD does not support $bad_metric"
  296.     fi
  297.  
  298.     error=`grep 'Metric not supported' $tmp.cntrs`
  299.     if [ "$error" ]
  300.     then
  301.     _metric_err "PMCD does not support R10000 event counters"
  302.     fi
  303.  
  304. # check out if cannot connect to PMCD 
  305.     if grep 'Cannot connect to PMCD' $tmp.cntrs > /dev/null
  306.     then
  307.     _metric_err "Cannot connect to PMCD"
  308.     fi
  309.  
  310. # check for unavailability        
  311.     if grep 'No value(s) available' $tmp.cntrs > /dev/null 
  312.     then
  313.         _metric_warn "R10000 event counter(s) unavailable"
  314.     fi
  315.  
  316. # check for unavailability        
  317.     if grep 'Information not currently available' $tmp.cntrs > /dev/null 
  318.     then
  319.         _metric_warn "R10000 event counter(s) unavailable"
  320.     fi
  321.  
  322. fi
  323.  
  324.  
  325. # --- Get instance information from metrics ---
  326. [ $has_routers = true ] && _get_router_metrics "send_util"
  327. [ $has_routers = true ] && _get_router_metrics "recv.total_util"
  328.  
  329.  
  330. # ----------------------------------------------------------
  331. # --- Output the config file ---
  332.  
  333. cat << EOF >> $tmp.conf
  334. _label 5 9 $host
  335.  
  336. _label 5 20 "CPU"
  337.  
  338. _colourlist cpuColours (blue3 red3 yellow3 cyan3 green3)
  339.  
  340. _multibar 5 22 55 6
  341.     _update 5.000000
  342.     _metrics (
  343.         irix.kernel.all.cpu.user
  344.         irix.kernel.all.cpu.sys
  345.         irix.kernel.all.cpu.intr
  346.         irix.kernel.all.cpu.wait.total
  347.         irix.kernel.all.cpu.idle
  348.     )
  349.     _maximum 0.0
  350.     _colourlist cpuColours
  351.  
  352. _label 5 38 "Load"
  353.  
  354. _bargraph 5 39 55 30
  355.     _update 5.000000
  356.     _metric irix.kernel.all.load["1 minute"]
  357.     _max 1.0
  358.  
  359. _label 5 79 "Free Mem"
  360.  
  361. _bar 5 81 55 6
  362.     _update 5.000000
  363.     _metric irix.mem.freemem
  364.     _max 6442450944
  365.     _color blue
  366. EOF
  367.  
  368. # ----------------------------------------------------------
  369.  
  370. if [ $has_evctrs = true ]
  371. then
  372.     cat << EOF >> $tmp.conf
  373. _label 75 20 "Events"
  374.  
  375. _colourlist eventColors ( "rgbi:0.3/0.0/1.0" "rgbi:1.0/0.9/0.0" )
  376.  
  377. _bar 75 22 45 6
  378.     _update 5.000000
  379.     _metric hw.r10kevctr.grad.fp
  380.     _colour green
  381. _label 122 27 "mflop"
  382.  
  383. _multibar 75 32 45 6
  384.     _update 5.000000
  385.     _metrics (
  386.     hw.r10kevctr.pcache.imiss
  387.     hw.r10kevctr.pcache.dmiss
  388.     )
  389. _colourlist eventColors
  390. _label 122 37 "1$ miss"
  391.  
  392. _multibar 75 42 45 6
  393.     _update 5.000000
  394.     _metrics (
  395.     hw.r10kevctr.scache.imiss
  396.     hw.r10kevctr.scache.dmiss
  397.     )
  398. _colourlist eventColors
  399. _label 122 47 "2$ miss"
  400.  
  401. _multibar 75 52 45 6
  402.     _update 5.000000
  403.     _metrics (
  404.     hw.r10kevctr.tlb
  405.     hw.r10kevctr.vcc
  406.     )
  407. _colourlist eventColors
  408. _label 122 57 "tlb/vcc"
  409.  
  410. _bar 75 62 45 6
  411.     _update 5.000000
  412.     _metric irix.swap.pagesout
  413.     _color red
  414. _label 122 67 "pageout"
  415.  
  416. EOF
  417. fi # has r10K
  418.  
  419.  
  420. # ----------------------------------------------------------
  421. # --- Router check ---
  422.  
  423. if [ $has_routers = true ]
  424. then
  425.     cat << EOF >> $tmp.conf
  426. _actions routerActions (
  427.     "pmchart"        "pmchart -c /var/pcp/config/pmchart/Disk -h $host"
  428.     "dkvis *"        "dkvis -h $host" _default
  429. )
  430.  
  431.  
  432. _label 5 98 "Router Util"
  433.     _actions routerActions
  434.  
  435. _legend routerLegend (
  436.     _default    green3
  437.     5        yellow
  438.     10        orange
  439.     20        red
  440. )
  441. EOF
  442.  
  443.     # router coordinates
  444.  
  445.     # Wraparound is for when to go down to next row of leds
  446.     # Really need to know the width of a label 
  447.     wrap_around=170
  448.     routerX=5
  449.     ledX_start=32
  450.     ledY_start=102
  451.     ledX_gap=10
  452.     ledY_gap=10
  453.     led_width=7
  454.     led_height=7
  455.     readonly routerX
  456.     readonly wrap_around
  457.     readonly ledX_start
  458.     readonly ledY_start
  459.     readonly ledX_gap
  460.     readonly ledY_gap
  461.     readonly led_width
  462.     readonly led_height
  463.  
  464.     ledX=$ledX_start
  465.     ledY=$ledY_start
  466.  
  467.     labelY=`expr $ledY + 6`
  468.     cat << EOF >> $tmp.conf
  469. _label $routerX $labelY "send"
  470. EOF
  471.  
  472.     _print_router_leds send_util
  473.  
  474.     ledX=$ledX_start
  475.     ledY=`expr $ledY + $ledY_gap`
  476.  
  477.     labelY=`expr $ledY + 6`
  478.     cat << EOF >> $tmp.conf
  479. _label $routerX $labelY "recv"
  480. EOF
  481.  
  482.     _print_router_leds recv.total_util
  483.  
  484. fi # has routers
  485.  
  486. $verbose && cat $tmp.conf
  487. eval /usr/sbin/pmgadgets <$tmp.conf $args -xrm "'*iconName: pmgevctr'"
  488.